# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# $Id: views.py 17 2008-04-01 14:30:47Z semente $
# ----------------------------------------------------------------------------
#
#  Copyright (c) 2008 Guilherme Mesquita Gondim
#
#  This file is part of django-fleshin.
#
#  django-fleshin is free software under terms of the GNU General
#  Public License version 3 (GPLv3) as published by the Free Software
#  Foundation. See the file README for copying conditions.
#

from django.views.generic.list_detail import object_detail
from django.views.generic.list_detail import object_list
from fleshin.models import Photo, Album

def photo_detail(request, album=None, *args, **kwargs):
    return object_detail(request, *args, **kwargs)

def photo_list(request, album=None, *args, **kwargs):
    """
    A thin wrapper around ``django.views.generic.list_detail.object_list``
    which creates a ``QuerySet`` containing only photos from ``album``
    argument, if specified.
    """
    if album:
        kwargs['queryset'] = kwargs['queryset'].filter(album__slug__exact=album)
        try:
            album_object = Album.objects.get(slug__exact=album)
            kwargs['extra_context']['album'] = album_object
        except KeyError:
            kwargs['extra_context'] = {'album': album_object}
    return object_list(request, *args, **kwargs)
